﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CourseUtils;
using System.IO;

namespace _4
{
    class Program4
    {
        static void Main(string[] args)
        {
            //CeliyDelitel();
            //RevChislo();
            //Fibonachi();
            //ReadFromFile();
            //FileCreate();
            //Factorial();
            //RandomNumber();
            Numbers();

        }

        
        static void CeliyDelitel()
        {
            int delitel1 = 2;
            int chislo = CourseUtils.IOHelpers.ReadIntFromConsole("введите число");
            int delitel = 0;
            int ostatok;
            int[] massiv = new int [100];
            int schotchik = 0;
            
            while (delitel1 < chislo)
            {
                ostatok = chislo % delitel1;
                if (ostatok == 0)
                {
                    delitel = delitel1;
                    Console.WriteLine(delitel);
                    massiv[schotchik] = delitel1;
                    ++schotchik;
                }
                delitel1 = delitel1 + 1;
            }

            int max = massiv.Max();
            int min = massiv[0];


            Console.WriteLine("max: {0}\n  min: {1}", max, min);
            //Console.WriteLine(delitel);
            Console.ReadKey();
        }

        static void RevChislo()
        {
            int chislo = CourseUtils.IOHelpers.ReadIntFromConsole("введите число");
            int n = 0;

            while (chislo != 0)
            {
                n = n * 10 + chislo % 10;

                chislo = chislo / 10;
            }
            Console.WriteLine(n);
            Console.ReadKey();

        }

        static void Fibonachi()
        {


            int i = CourseUtils.IOHelpers.ReadIntFromConsole("Введите кол-во чисел ряда Фибоначчи");

            int schotchik = 3;
            int Int1 = 0;
            int Int2 = 1;
            int result = 0;

            if (i >= 2)
            {
                Console.Write("0 ");
                Console.Write("1 ");
            }
                
            if (i < 2)
                Console.WriteLine("0");
            
            while (schotchik <= i)
            {

                result = Int1 + Int2;
                Int1 = Int2;
                Int2 = result;

                Console.Write("{0} ",result);
                schotchik = schotchik + 1;
            }

            Console.ReadKey();
        
        }

        static void ReadFromFile()
        {
            StreamReader inputFile = File.OpenText("C://input.txt");
            string line = null;
            line = inputFile.ReadLine();
            String razdelitel = "|";
            string[,] mas = new string[8, 2];
            string key;
            string val;

            while (line != null)
            {
                string[] keyVal = line.Split(new char[] {'|'});
                




            }
            
            
            Console.WriteLine(line);
            Console.ReadKey();        
        
        
        
        
        
        
        
        
        }

        static void FileCreate()
        {
            //Directory.CreateDirectory("C://LAB");

            char c = 'A';
            string extention = "xxx";

            while (c<='Z')
            {

                Directory.CreateDirectory(Environment.CurrentDirectory + "\\" + c);

                int i = 0;

                while(i<1000)
                {

                    File.Create(String.Format("{3}\\{0}\\{1}.{2}", c, i, extention, Environment.CurrentDirectory));
                    i++;

                }
                c++;


            }


        }
    
        static void Factorial()
        {

            int i = CourseUtils.IOHelpers.ReadIntFromConsole("Введите чисело");
            uint n =1;
            double rez = 1;

            while (n<=i)
            {

                rez *= n;
                //Console.WriteLine("{0}!= {1}",n, rez);

                n++;
            }


            Console.WriteLine("{0}!= {1}",n-1, rez);
            Console.ReadKey();

        }

        static void RandomNumber()//new
        {

            int numbersAmount = CourseUtils.IOHelpers.ReadIntFromConsole("Введите количество чисел");
            int filesAmount = CourseUtils.IOHelpers.ReadIntFromConsole("Введите количество файлов");

            for (int j = 0; j < filesAmount; j++)
            {
                StringBuilder strToFile = new StringBuilder();

                for (int i = 0; i < numbersAmount; i++)
                {
                    int randomNumber = GetRandomValue();

                    strToFile.Append(String.Format(" {0}", randomNumber));
                }

                File.WriteAllText("output" + j + ".txt", strToFile.ToString());
            }
        }

        static int GetRandomValue() //new
        {
            Random rnd = new Random();
            return rnd.Next();
        }

        static void MaxMin ()
        {
            String str = File.ReadAllText("output0.txt");
            String number = "";

            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == ' ')
                {
                    //delimeter is found
                    if (!String.IsNullOrEmpty(number))
                    {
                        int numberInt = Int32.Parse(number);
                    }
                    number = "";
                }
                else
                {
                    number += str[i];
                }


        }
    }
    
        static void Numbers()
        {
            int n = CourseUtils.IOHelpers.ReadIntFromConsole("введите число");
            int[] storage = new int[n];
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("Введите {0}-ое число;", i + 1);
                int temp = CourseUtils.IOHelpers.ReadIntFromConsole("введите число");
                storage[i]=temp;
            }

            RevMass(storage);
            //Console.WriteLine("Сумма {0}",CalcArreySum(storage));
            //Console.WriteLine("max {0}", CalcMaxValue(storage));
            //Console.WriteLine("min {0}", CalcMinValue(storage));
            //------Console.WriteLine("RevMass {0}", RevMass(storage));
            Console.ReadKey();
        }
        
        static int CalcArreySum (int[] storage)
        {
            int length = storage.Length;
            int summ=0;
            for (int i = 0;i<length;i++)
            {
                summ=summ+storage[i];

            }
            
            return summ;
        }

        static int CalcMaxValue(int[] storage)
        {
            int max = Int32.MinValue;
            for (int i = 0; i < storage.Length; i++)
            {

                if (max < storage[i])
                    max = storage[i];
            }
            return max;
        }

        static int CalcMinValue(int[] storage)
        {
            if (storage == null)
                throw new ArgumentException("arrey");

            int max = Int32.MaxValue;
            for (int i = 0; i < storage.Length; i++)
            {
                if (max > storage[i])
                    max = storage[i];
            }
            return max;
        }

        static int[] RevMass(int[] storage)
        {
            int[] revMassiv = new int[storage.Length];

            int b = storage.Length-1;
            for (int i = 0; i < storage.Length; i++)
            {
                
                revMassiv[i]=storage[b];
                b--;
                Console.WriteLine("{1}) {0}", revMassiv[i],i+1);
            }

            return revMassiv;
        }

        static void CreditCalc ()
        {
            decimal summ = CourseUtils.IOHelpers.ReadIntFromConsole("Сумма кредита");
            decimal srok = CourseUtils.IOHelpers.ReadIntFromConsole("Срок кредита (в месяцах)");
            decimal stavka = CourseUtils.IOHelpers.ReadIntFromConsole("Процентная ставка");






        }







    
    }
}